<template>
	<view class="dynamics-page">
		<!-- 列表内容 -->
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<view class="top-box">
				<view class="pageBg-box">
					<image :src="pageBg" class="pageBg" v-if="pageBg"></image>
					<view class="" style="position: absolute; right: 30rpx;bottom: 16rpx;">
						<u-icon name="bell" size="30" color="#000000"></u-icon>
					</view>
				</view>

				<view class="banner-box">
					<u-swiper :list="bannerList" keyName="thumb_image" height="200rpx" @click="clickBanner"></u-swiper>
				</view>
			</view>
			<view class="dynamics-list">
				<view class="dynamics-item" v-for="(item, index) in dataList" :key="index">
					<image :src="$OssUrl(item.user.avatar)" class="item-left" mode="aspectFill" @click="lookUserDetail(item)"
						v-if="item.user.avatar"></image>
					<view class="item-right">
						<view class="item-title">
							<view class="item-user">
								<view class="name">{{item.user.nickname}}</view>
								<image src="../../static/common/icon_vip.png" class="icon-vip" v-if="item.user.vip"></image>
								<image src="../../static/common/icon_hy.png" class="icon-user" v-else></image>
							</view>
						</view>
						<view class="item-introduce">
							<view class="city-box" v-if="item.is_city==1">
								<u-icon name="map-fill" size="12" color="#9A9A9A"></u-icon>{{item.city}} |
							</view>
							{{item.createtime_text}}
						</view>
						<view class="item-content">{{item.content}}</view>
						<view class="item-images">
							<u-album :urls="item.images_text" maxCount="3" :multipleSize="80" :singleSize="152"
								singleMode="widthFix"></u-album>
						</view>
						<!-- 点赞 -->
						<view class="item-heart" @click="toggleFavForum(item)">
							<u-icon name="heart" size="14" color="#9A9A9A" v-if="!item.is_fav_count"></u-icon>
							<u-icon name="heart-fill" size="14" color="#F169F6" v-if="item.is_fav_count"></u-icon>
							<view style="color: #9A9A9A;" v-if="!item.is_fav_count"> 点赞</view>
							<view style="color: #F169F6;" v-if="item.is_fav_count"> 点赞</view>
						</view>
					</view>
				</view>
			</view>
		</z-paging>

		<view class="publish-btn" @click="$u.throttle(dynamicsSubmit,2000)">
			<image src="../../static/common/icon_fj.png" class="icon"></image>
			<text class="publish-text">发布</text>
		</view>
		<vipPopup :show="showVip" @close="showVip=false" @success="vipRechageSuccess"></vipPopup>
		<authentication :show="showAuth" @close="showAuth=false" @success="authSuccess"></authentication>
		<userPopup :show="showUser" @close="showUser=false" @followSuccess="followSuccess" :user_id="to_user_id">
		</userPopup>
	</view>
</template>
<script>
	import {
		mapGetters
	} from "vuex";
	import vipPopup from '@/components/VipPopup.vue';
	import authentication from '@/components/Authentication.vue';
	import userPopup from '@/components/UserPopup.vue';
	export default {
		data() {
			return {
				pageBg: '/static/common/page_bg2.png',
				bannerList: [],
				dataList: [],
				userInfo: null,
				showVip: false,
				showAuth: false,
				showUser: false,
				to_user_id: null
			}
		},
		components: {
			vipPopup: vipPopup,
			userPopup: userPopup,
			authentication: authentication
		},
		computed: mapGetters(['isLogin']),
		onLoad() {
			this.getBannerList()
		},
		onBackPress() {
			if (this.showUser) {
				this.showUser = false
			}
		},
		onShow() {
			this.refreshList()
			if (this.isLogin) {
				this.getUserInfo()
			}
		},
		methods: {
			clickBanner(e) {},
			lookUserDetail(item) {
				this.to_user_id = item.user_id
				this.showUser = true
			},
			//关注成功
			followSuccess() {},
			//vip充值成功
			vipRechageSuccess() {
				this.showVip = false
				this.getUserInfo()
			},
			getUserInfo() {
				this.$Api['user'].getUserInfo().then(res => {
					this.userInfo = res.data
					if (res.data.gender == 0) {
						return this.$Tips('/pages/mine/select-sex')
					}
					if (res.data.gender != 0 && !res.data.parent_user_id) {
						return this.$Tips('/pages/mine/improve-user')
					}
				})
			},
			toggleFavForum(item) {
				this.$Api['user'].toggleFavForum({
					forum_id: item.id
				}).then(res => {
					this.refreshList()
				})
			},
			//提交认证
			authSuccess() {
				this.showAuth = false
				this.$Tips('/pages/authentication/authentication')
			},
			dynamicsSubmit() {
				if (!this.isLogin) {
					return this.$Tips('/pages/login/login')
				}
				if (this.userInfo.gender == 1) {
					if (!this.userInfo.vip) {
						this.showVip = true
					} else {
						this.$Tips('/pages/dynamics/submit')
					}
				} else {
					if (this.userInfo.is_auth != 1) {
						this.showAuth = true
					} else {
						this.$Tips('/pages/dynamics/submit')
					}
				}
			},
			getBannerList() {
				this.$Api['common'].getBannerList({
					group: 'index'
				}).then(res => {
					this.bannerList = res.data
				})
			},
			refreshList() {
				if (this.$refs.paging) {
					this.$refs.paging.refresh();
				}
			},
			queryList(pageNo, pageSize) {
				this.$Api.user.getForumList({
					page: pageNo,
					limit: pageSize,
				}).then(res => {
					this.$refs.paging.complete(res.data.data);
				}).catch(res => {
					this.$refs.paging.complete(false);
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.dynamics-page {
		width: 100%;
		min-height: 100vh;
		position: relative;
		background-color: #ffffff;

		.top-box {
			position: relative;

			.pageBg-box {
				position: relative;

				.pageBg {
					position: relative;
					width: 100%;
					height: 176rpx;
				}
			}

			.banner-box {
				height: 200rpx;
				margin: 0 28rpx 0rpx;
				border-radius: 24rpx;
			}

		}
	}

	.dynamics-list {
		padding: 38rpx 50rpx 0 28rpx;
	}

	.dynamics-item {
		display: flex;
		align-items: center;
		margin-bottom: 30rpx;
		box-sizing: border-box;
		border-radius: 28rpx;
		background: #ffffff;

		.item-left {
			width: 88rpx;
			height: 88rpx;
			border-radius: 50%;
			margin-right: 22rpx;
			align-self: flex-start;
		}

		.item-right {
			flex: 1;

			.item-title {
				font-size: 32rpx;
				color: #323334;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.item-user {
					display: flex;
					align-items: center;

					.name {
						font-size: 32rpx;
					}

					.icon-user {
						width: 28rpx;
						height: 28rpx;
						margin-left: 8rpx;
					}

					.icon-vip {
						margin-left: 8rpx;
						width: 94rpx;
						height: 28rpx;
					}
				}
			}

			.item-introduce {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				color: #9A9A9A;
				margin-top: 16rpx;

				.city-box {
					display: inline-flex;
					align-items: center;
					margin-right: 8rpx;
				}
			}

			.item-content {
				font-size: 28rpx;
				color: #222222;
				margin: 30rpx 0rpx;

			}

			.item-heart {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				margin-top: 20rpx;

				.heart {
					margin-right: 10rpx;
				}

				.heart-fill {
					margin-right: 10rpx;
				}
			}
		}
	}


	.publish-btn {
		position: fixed;
		right: 30rpx;
		bottom: 80rpx;
		width: 156rpx;
		height: 84rpx;
		background: linear-gradient(135deg, #F169F6 0%, #FF4A8C 100%);
		border-radius: 16rpx;
		display: flex;
		align-items: center;
		justify-content: center;

		.icon {
			width: 36rpx;
			height: 36rpx;
		}

		.publish-text {
			color: #FFFFFF;
			font-size: 28rpx;
			margin-left: 16rpx;
		}
	}
</style>